import Taro, {Component} from '@tarojs/taro'
import {View, Text, Button, RichText} from '@tarojs/components'
import {connect} from '@tarojs/redux'

import './topicInfo.scss'

class TopicInfo extends Component {

  editTopic () {
    Taro.redirectTo({url: '/pages/publish/publish?edit=1'})
  }

  render () {
    let {topicInfo} = this.props
    return (
      <View className='topic-info'>
        <View className='topic-info-head'>
          <View className='topic-info-head-title'>
            {/* <Text>置顶</Text> */}
            <Text>{topicInfo.title}</Text>
          </View>
          <View className='topic-info-head-pie'>
            <Text>{topicInfo.create_at}</Text>
            <Text>{topicInfo.author ? topicInfo.author.loginname: ''}</Text>
            <Text>{topicInfo.visit_count + '次浏览'}</Text>
          </View>
        </View>
        <Image className='editImg' src={require('../../assets/images/edit.png')} onClick={this.editTopic.bind(this, topicInfo)} />
        <View className='topic-info-body'>
          <RichText nodes={topicInfo.content ? topicInfo.content.replace(/\<img/gi, '<img style="max-width:100%;height:auto"') : ''} />
        </View>
      </View>
    )
  }
}

TopicInfo.defaultProps = {
  topicInfo: {}
}

export default TopicInfo